package com.sen.common.user.config;

import cn.hutool.core.util.StrUtil;
import com.alibaba.ttl.TransmittableThreadLocal;
import com.sen.common.common.bo.PeopleInfo;
import com.sen.common.common.constrant.CommonConstrant;

/**
 * @author esjiang
 */
public class UserContextHolder {

    private static final ThreadLocal<String> CONTEXT = new TransmittableThreadLocal<>();

    private static final ThreadLocal<PeopleInfo> PEOPLE = new TransmittableThreadLocal<>() ;

    public static void setUser(String userName) {
        CONTEXT.set(userName);
    }

    public static void setPeople(PeopleInfo peopleInfo){
        PEOPLE.set(peopleInfo);
    }

    public static String getUser() {
        return CONTEXT.get();
    }

    public static PeopleInfo getPeople(){
        return PEOPLE.get();
    }

    public static void clear() {
        CONTEXT.remove();
        PEOPLE.remove();
    }

    /**
     * 判断是否是超级管理员
     * @return
     */
    public static boolean isSuperAdmin(){
        return StrUtil.equals(getUser(), CommonConstrant.SUPER_ADMIN) ;
    }
}
